<?php
$this->breadcrumbs=array(
	'Orders'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'List Order', 'url'=>array('index')),
	array('label'=>'Create Order', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('order-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<h1>Manage Orders</h1>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?> |
<?php echo CHtml::link('Print EMS', '#', array('onclick'=>'viewListEms();$("#mydialog").dialog("open"); return false;',));?> |
<?php if(isset($_GET['print'])):?>
    <a href="?" target="">Main View</a> |
<?php else:?>
    <a href="?print" target="">Full View</a>
<?php endif;?>

<div class="search-form" style="display:none;">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div>

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'order-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
    'selectableRows'=>2,
//    'htmlOptions'=>array('style'=>'table-layout: fixed;'),
	'columns'=>array(
        array(
			'class'=>'CCheckBoxColumn',
			'id'=>'selected_ids',
			'value'=>$model->id,
		),
        'id',
//		'create_time',
//        array(
//            'name'=>'update_time',
//            'value'=>$model->update_time,
//            'filter'=>array('1'=>'วันนี้','2'=>'เมื่อวาน','3'=>'เมื่อวานซืน','4'=>'7วันที่แล้ว','5'=>'1เดือนที่ผ่านมา')
//        ),
        'update_time',
        'sender',
//        array(
//            'name'=>'sender',
//            'value'=>$model->sender
//        ),
		'customer',
		//'address',
		'products',
		'transferred',
		'bank',
		'date_trans',
		'status',
//		array(
//            'name'=>'note',
//            'value'=>$model->note,
//            'htmlOptions'=>array('style'=>'word-wrap:break-word;')
//        ),
        'note',
		array(
			'class'=>'CButtonColumn',
		),
	),
));


$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'mydialog',
    // additional javascript options for the dialog plugin
    'options'=>array(
        'title'=>'EMS LIST',
        'autoOpen'=>false,
    ),
));

    echo '<div id="viewEms"></div>';

$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
<script type="text/javascript">

    function viewListEms(){
        var selected_ids = [];
        var urlSelected_id = '';
        $('input:checkbox[name="selected_ids[]"]:checked').each(function(index) {
            if(index > 0 ){
                urlSelected_id+=',';
            }
            urlSelected_id+=$(this).val();
        });

        if(urlSelected_id == '' || urlSelected_id == undefined)
            return false;

        $.ajax({
          url: '<?php echo $this->createUrl('order/getems');?>?list_id='+urlSelected_id,
          dataTypes: 'html',
          success: function(data) {
            if(data){
                $('#viewEms').html(data);
            }
          }
        });
    }

$(function(){
//    $(":input[name='Order[create_time]']").attr("disabled", true);
//    $(":input[name='Order[update_time]']").attr("disabled", true);
//    $(":input[name='Order[date_trans]']").attr("disabled", true);

//    $(":input[name='Order[update_time]']").css({'cursor':'pointer'});
//    $(":input[name='Order[create_time]']").css({'cursor':'pointer'});
//    $(":input[name='Order[date_trans]']").css({'cursor':'pointer'});
});
</script>